<template>
	<view class="content">
		<view class="title">子组件B</view>
		<view class="b-box">
			ComA组件传进来的值：
			<text class="intent-text-box">{{result}}</text>
		</view>
		<view class="b-box" style="margin: 10rpx;">
			<text>回传值：</text>
			<input type="text" v-model="callbackValue" style="color: lightskyblue;" />
			<button @click="sendOutside()" size="mini">回传</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				result: '',
				callbackValue: ''
			}
		},
		created() {
			uni.$on('sendToComB', (dataFromA) => {
				console.warn("----子组件B接收ComA数据----->", dataFromA);
				this.result = dataFromA; 
			});
		},
		methods: {
			sendOutside() {
				console.warn("----子组件B回传值给父组件----->", this.callbackValue);

				this.$emit('callBackFun', this.callbackValue);
			}
		},

		onUnload() {
			uni.$off('sendToComB');
		}
	}
</script>

<style scoped>
	.content {
		margin: 30rpx 20rpx;
		padding: 25rpx;
		border: 1px solid #ffccd5;
		border-radius: 12rpx;
		background-color: #fff5f7;
	}
	.title {
		font-size: 50rpx;
		font-weight: 500;
		color: #333;
		margin-bottom: 35rpx;
	}
	.b-box {
		display: flex;
		align-items: center;
		font-size: 32rpx;
		color: #333;
		margin-bottom: 25rpx;
	}
	.intent-text-box {
		color: lightskyblue;
		font-weight: bold;
		margin-left: 10rpx;
	}

	input {
		flex: 1;
		margin: 0 15rpx;
		padding: 12rpx;
		border: 1px solid #eee;
		border-radius: 8rpx;
		font-size: 30rpx;
	}
	button {
		margin-left: 10rpx;
	}
</style>